
package br.com.senacrs.control;

import br.com.senacrs.dao.Dao;
import br.com.senacrs.validation.Validation;
import java.util.List;

public class GenericCR<T> implements ControlCR<T> {
    
    private Dao dao;
    private Validation validation;
    
    @Override
    public void insert(T objeto) {
        this.validation.validateInsert(objeto);
        this.dao.insert(objeto);
    }

    @Override
    public void delete(T objeto) {
        this.validation.validateDelete(objeto);
        this.dao.delete(objeto);
    }

    @Override
    public void update(T objeto) {
        this.validation.validateUpdate(objeto);
        this.dao.update(objeto);
    }

    @Override
    public List<T> selectAll() {
        this.validation.validateSelectAll();
        return this.dao.selectAll();
    }

    @Override
    public List<T> selectAllOrderBy(String order) {
        this.validation.validateSelectAllOrderBy(order);
        return this.dao.selectAllOrderBy(order);
    }

    @Override
    public T selectOne(Long id) {
        this.validation.validateSelectOne(id);
        return (T) this.dao.selectOne(id);
    }

    @Override
    public T selectOneGet(Long id) {
        this.validation.validateSelectOneGet(id);
        return (T) this.dao.selectOneGet(id);
    }

    @Override
    public List<T> selectWhere(String criterio, String string) {
        this.validation.validateSelectWhere(criterio, string);
        return this.dao.selectWhere(criterio, string);
    }

    @Override
    public List<T> selectWhere(String criterio, Long valor) {
        this.validation.validateSelectWhere(criterio, valor);
        return this.dao.selectWhere(criterio, valor);
    }

    @Override
    public List<T> selectWhere(String criterio, String criterioJoin, Long valor) {
        this.validation.validateSelectWhere(criterio, criterioJoin, valor);
        return this.selectWhere(criterio, criterioJoin, valor);
    } 
}
